package com.example.basic;


import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

public class DownLoadPictuire extends Thread{
    private String name;
    private URL url;
    public DownLoadPictuire(String name,URL url){
        this.name=name;
        this.url=url;
    }
    public static void main(String[] args) throws MalformedURLException {
        DownLoadPictuire downLoadPictuire = null;
        DownLoadPictuire downLoadPictuire1=null;
        URL url = new URL("https://image.baidu.com/search/detail?ct=503316480&z=0&ipn=d&word=%E7%BE%8E%E5%A5%B3%E5%A4%B4%E5%83%8F%20%E7%BD%91%E7%BA%A2&step_word=&hs=0&pn=14&spn=0&di=7077204560107798529&pi=0&rn=1&tn=baiduimagedetail&is=0%2C0&istype=2&ie=utf-8&oe=utf-8&in=&cl=2&lm=-1&st=-1&cs=2591269703%2C18467681&os=1345277265%2C3696770367&simid=3461254577%2C393231184&adpicid=0&lpn=0&ln=1781&fr=&fmq=1650594865739_R&fm=result&ic=&s=undefined&hd=&latest=&copyright=&se=&sme=&tab=0&width=&height=&face=undefined&ist=&jit=&cg=&oriquery=&objurl=https%3A%2F%2Fgimg2.baidu.com%2Fimage_search%2Fsrc%3Dhttp%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F201611%2F04%2F20161104201812_JV5Lz.thumb.1000_0.jpeg%26refer%3Dhttp%3A%2F%2Fc-ssl.duitang.com%26app%3D2002%26size%3Df9999%2C10000%26q%3Da80%26n%3D0%26g%3D0n%26fmt%3Dauto%3Fsec%3D1653186864%26t%3D84e892d17c9e79d383eec02667b41c7a&gsm=3c&rpstart=0&rpnum=0&islist=&querylist=&nojc=undefined&dyTabStr=MCw0LDEsNiw1LDMsNyw4LDIsOQ%3D%3D");
            downLoadPictuire = new DownLoadPictuire("小明",url);
            downLoadPictuire1 = new DownLoadPictuire("小黑", url);
        downLoadPictuire.start();
        downLoadPictuire1.start();
    }
    public void download(URL url) throws IOException {
        FileUtils.copyURLToFile(url,new File("E:\\java\\springcloud\\thread\\src\\com\\example\\"+this.name+".jpg"));
    }

    @Override
    public void run() {
        try {
            this.download(url);
            System.out.println(this.name+"下载图片成功");
        } catch (IOException e) {
            System.out.println(this.name+"下载图片失败");
        }
    }
}
